package Greed;

public class JumpGame2 {
    public int jump(int[] nums) {
         int right=0,left=0,ret=0,maxpos=0;
         int n=nums.length;
         while(left<=right){
             if(maxpos>=n-1){
                 return ret;
             }
             for (int i = left; i <= right ; i++) {
                 maxpos=Math.max(maxpos,nums[i]+i);
             }
             left=right+1;
             right=maxpos;
             ret++;
         }
         return -1;
    }
}
